package com.usian.ai.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.usian.ai.common.Result;
import com.usian.ai.common.vo.InterviewerReqVo;
import com.usian.ai.common.vo.PageVo;
import com.usian.ai.mapper.InterviewerMapper;
import com.usian.ai.pojo.Interviewer;
import com.usian.ai.service.InterviewerService;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @TODO:
 * @Author:baimu
 * @Date:2024 12 09 09 45
 **/

@Service
public class InterviewerServiceImpl extends ServiceImpl<InterviewerMapper, Interviewer>
implements InterviewerService {


    @Override
    public Result listInterviewers(PageVo pageVo) {
        QueryWrapper<Interviewer> interviewerQueryWrapper = new QueryWrapper<>();
        interviewerQueryWrapper.lambda().orderByDesc(Interviewer::getId);
        Page<Interviewer> objectPage = new Page<>(pageVo.getPageNum(), pageVo.getPageSize());
        Page<Interviewer> interviewerPage = this.baseMapper.selectPage(objectPage, interviewerQueryWrapper);
        return Result.ok(interviewerPage);
    }

    @Override
    public Result addInterviewer(InterviewerReqVo interviewerReqVo) {

        Interviewer interviewer = new Interviewer(interviewerReqVo.getAiName(),interviewerReqVo.getImage());
        interviewer.setCreateTime(new Date());
        interviewer.setUpdatedTime(new Date());

        int insert = this.baseMapper.insert(interviewer);
        return Result.ok(insert);
    }
}
